local DIY = require "packages/diy_utility/diy_utility"

local tuibing = fk.CreateSkill{
  name = "kq__tuibing",
}

tuibing:addAcquireEffect(function (self, player, is_start)
  player.room:addSkill("#CenterArea")
end)

tuibing:addEffect("viewas",{
    anim_type = "support",
    pattern = "lure_tiger,nullification,reinforcement",
    interaction = function(self,player)
      local slashs = #table.filter(Fk:currentRoom():getBanner("@$CenterArea"), function(id)
            return Fk:getCardById(id).trueName == "slash"
        end)
        local all_names = {}
        if slashs == 0 and player:getMark("tuibing1-turn")==0 then
          all_names = {"lure_tiger"}
        elseif slashs == 1 and player:getMark("tuibing2-turn")==0 then
          all_names = {"nullification"}
        elseif slashs == 2  and player:getMark("tuibing3-turn")==0 then
          all_names = {"reinforcement"}
        end
        local names = player:getViewAsCardNames(tuibing.name,all_names)
        if #names > 0 then
            return UI.ComboBox { choices = names, all_choices = all_names }
        end
    end,
    prompt = function (self, player, selected_cards, selected)
        if self.interaction.data == "lure_tiger" then
            return "#kq__tuibing1"
        elseif self.interaction.data == "nullification" then
            return "#kq__tuibing2"
        elseif self.interaction.data == "reinforcement" then
            return "#kq__tuibing3"
        end
        return "#kq__tuibing0"
    end,
    card_filter =  Util.FalseFunc,
    before_use = function(self, player)
      if self.interaction.data == "lure_tiger" then
          player.room:addPlayerMark(player, "tuibing1-turn")
        elseif self.interaction.data == "nullification" then
          player.room:addPlayerMark(player, "tuibing2-turn")
        elseif self.interaction.data == "reinforcement" then
          player.room:addPlayerMark(player, "tuibing3-turn")
        end
    end,
    view_as = function(self, player, cards)
        local card = Fk:cloneCard(self.interaction.data)
        card.skillName = tuibing.name
        card:addSubcards(cards)
        return card
    end,
    enabled_at_play = function (self, player)
        local slashs = #table.filter(Fk:currentRoom():getBanner("@$CenterArea"), function(id)
            return Fk:getCardById(id).trueName == "slash"
        end)
        if player:usedSkillTimes(tuibing.name, Player.HistoryTurn) < 3 then
            return (slashs == 0 and player:getMark("tuibing1-turn")==0) or (slashs == 2 and player:getMark("tuibing3-turn")==0 )
        end
    end,
    enabled_at_response = function (self, player)
        local slashs = #table.filter(Fk:currentRoom():getBanner("@$CenterArea"), function(id)
            return Fk:getCardById(id).trueName == "slash"
        end)
        return player:usedSkillTimes(tuibing.name, Player.HistoryTurn) < 1 and slashs == 1
    end,
})


Fk:loadTranslationTable{
  ["kq__tuibing"] = "推兵",
  [":kq__tuibing"] = "每回合每种牌名限一次，若中央区【杀】的数量为0/1/2，你可以视为使用一张【调虎离山】/【无懈可击】／【增兵减灶】。",
  ["$kq__tuibing1"] = "以计推兵，渐喰其形。",
  ["$kq__tuibing2"] = "诈其循序，出奇而击。",
  ["#kq__tuibing1"] = "视为使用一张【调虎离山】",
  ["#kq__tuibing2"] = "视为使用一张【无懈可击】",
  ["#kq__tuibing3"] = "视为使用一张【增兵减灶】",
  ["#kq__tuibing0"] = "无法使用",
}



return tuibing